import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import { isWindow7 } from "@/utils/index";
export const Layout = () => import("@/layout/index.vue");

const WORKBENCH = import.meta.env.VITE_APP_WORKBENCH;
const window7 = isWindow7();
// const dashboard = () => import("@/views/dashboardWindows/index.vue");
// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },
  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/scanningCode",
    component: () => import("@/views/demo/scanningCode/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/iframePrint",
    component: () => import("@/views/demo/iframePrint/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/iframePrintCombine",
    component: () => import("@/views/demo/iframePrintCombine/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/iframePrintUnpack",
    component: () => import("@/views/demo/iframePrintUnpack/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/iframePrintUnit",
    component: () => import("@/views/demo/iframePrintUnit/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/iframePrintDelivery",
    component: () => import("@/views/demo/iframePrintDelivery/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/iframePrintReturn",
    component: () => import("@/views/demo/iframePrintReturn/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/iframePrintReturnDelivery",
    component: () => import("@/views/demo/iframePrintReturnDelivery/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/iframePrintSrmDelivery",
    component: () => import("@/views/demo/iframePrintSrmDelivery/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/printJsDemo",
    component: () => import("@/views/demo/printJsDemo/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/iframePrintDeliveryUnit",
    component: () => import("@/views/demo/iframePrintDeliveryUnit/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/iframePrintSrmDeliveryUnit",
    component: () =>
      import("@/views/demo/iframePrintSrmDeliveryUnit/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/iframePrintUnitOne",
    component: () => import("@/views/demo/iframePrintUnitOne/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/iframePrintReturnUnitOne",
    component: () => import("@/views/demo/iframePrintReturnUnitOne/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/mes",
    name: "DATASCREENMES",
    component: () => import("@/views/dataScreen/mes/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/jt",
    name: "DATASCREENJT",
    component: () => import("@/views/dataScreen/jt/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTScreen",
    name: "DATASCREENJTSCREEN",
    component: () => import("@/views/dataScreen/JTScreen/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTDashboard",
    name: "DATASCREENJTDASHBOARD",
    component: () => import("@/views/dataScreen/JTDashboard/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTScreen01",
    name: "DATASCREENJTSCREEN",
    component: () => import("@/views/dataScreen/JTScreen01/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTScreen02",
    name: "DATASCREENJTSCREEN02",
    component: () => import("@/views/dataScreen/JTScreen02/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTScreen03",
    name: "DATASCREENJTSCREEN03",
    component: () => import("@/views/dataScreen/JTScreen03/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTScreenCustomize",
    name: "DATASCREENJTSCREENCUSTOMIZE",
    component: () => import("@/views/dataScreen/JTScreenCustomize/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTScreenCustomizeEam",
    name: "DATASCREENJTSCREENCUSTOMIZEEAM",
    component: () =>
      import("@/views/dataScreen/JTScreenCustomizeEam/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTCustomizeScreen",
    name: "DATASCREENJTCUSTOMIZESCREEN",
    component: () => import("@/views/dataScreen/JTCustomizeScreen/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTMoldProduceScreen",
    name: "DATASCREENJTMOLDPRODUCESCREEN",
    component: () => import("@/views/dataScreen/JTMoldProduceScreen/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTAlloyingChargeScreen",
    name: "DATASCREENJTALLOYINGCHARGESCREEN",
    component: () =>
      import("@/views/dataScreen/JTAlloyingChargeScreen/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTMoldMaintenanceScreen",
    name: "DATASCREENJTMOLDMAINTENANCESCREEN",
    component: () =>
      import("@/views/dataScreen/JTMoldMaintenanceScreen/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTAlloyingChargeScreen01",
    name: "DATASCREENJTALLOYINGCHARGESCREEN01",
    component: () =>
      import("@/views/dataScreen/JTAlloyingChargeScreen01/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTAlloyingChargeScreen02",
    name: "DATASCREENJTALLOYINGCHARGESCREEN02",
    component: () =>
      import("@/views/dataScreen/JTAlloyingChargeScreen02/index.vue"),
    meta: { hidden: true },
  },

  {
    path: "/dataScreen/JTAlloyingChargeScreen03",
    name: "DATASCREENJTALLOYINGCHARGESCREEN03",
    component: () =>
      import("@/views/dataScreen/JTAlloyingChargeScreen03/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTAlloyingChargeScreen04",
    name: "DATASCREENJTALLOYINGCHARGESCREEN04",
    component: () =>
      import("@/views/dataScreen/JTAlloyingChargeScreen04/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTAMoldTaskScreen",
    name: "DATASCREENJTAMOLDTASKSREEN",
    component: () => import("@/views/dataScreen/JTAMoldTaskScreen/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/dataScreen/JTSmeltScreen",
    name: "DATASCREENJTSMELTSCREEN",
    component: () => import("@/views/dataScreen/JTSmeltScreen/index.vue"),
    meta: { hidden: true },
  },
  
  {
    path: "/saveYear",
    name: "SaveYear",
    component: () => import("@/views/demo/saveYear/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/CapabilityMatrix",
    name: "CapabilityMatrix",
    component: () => import("@/views/demo/CapabilityMatrix/index.vue"),
    meta: { hidden: true },
  },

   {
    path: "/iframePrintSchedule",
    component: () => import("@/views/demo/iframePrintSchedule/index.vue"),
    meta: { hidden: true },
  },
  
  
  // {
  //   path: "/dataV1",
  //   name: "/dataV1",
  //   redirect: "/dataScreen/mes",
  //   children: [
  //     {
  //       path: "/dataScreen/mes",
  //       name: "DATASCREENMES",
  //       component: () => import("@/views/dataScreen/mes/index.vue"),
  //       meta: { hidden: true },
  //     },
  //   ],
  // },
  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        // component: () => import("@/views/dashboard/index.vue"),
        component: () =>
          window7
            ? import("@/views/dashboardWindows/index.vue")
            : import("@/views/dashboard/index.vue"),
        name: "Dashboard", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          id: "dashboard",
          title: "dashboard",
          icon: "work",
          affix: true,
          keepAlive: true,
          alwaysShow: false,
          applicationType: WORKBENCH,
        },
      },
      {
        path: "401",
        component: () => import("@/views/error-page/401.vue"),
        meta: { hidden: true },
      },
      {
        path: "404",
        component: () => import("@/views/error-page/404.vue"),
        meta: { hidden: true },
      },
      {
        path: "dynamic-table",
        component: () => import("@/views/demo/table/dynamic-table/index.vue"),
        name: "DynamicTable",
        meta: {
          title: "动态Table",
          hidden: true,
          roles: ["ADMIN"],
          keepAlive: true,
        },
      },
      {
        path: "drag-table",
        component: () => import("@/views/demo/table/drag-table.vue"),
        name: "DragTable",
        meta: {
          title: "拖拽Table",
          hidden: true,
          roles: ["ADMIN"],
          keepAlive: true,
        },
      },
      {
        path: "complex-table",
        component: () => import("@/views/demo/table/complex-table.vue"),
        name: "ComplexTable",
        meta: {
          title: "综合Table",
          hidden: true,
          roles: ["ADMIN"],
          keepAlive: true,
        },
      },
      {
        path: "common-table",
        component: () => import("@/views/demo/table.vue"),
        name: "CommonTable",
        meta: {
          title: "CommonTable",
          hidden: true,
          roles: ["ADMIN"],
          keepAlive: true,
        },
      },
      {
        path: "custom-table",
        component: () => import("@/views/demo/customTable/index.vue"),
        name: "CustomTable",
        meta: {
          title: "CustomTable",
          hidden: true,
          roles: ["ADMIN"],
          keepAlive: false,
        },
      },
      {
        path: "demo/srmPurchaseDemand",
        component: () => import("@/views/demo/srmPurchaseDemand/index.vue"),
        name: "SrmPurchaseDemand",
        meta: {
          title: "复杂表格DEMO",
          hidden: true,
          roles: ["ADMIN"],
          keepAlive: false,
        },
      },
      {
        path: "demo/CapabilityMatrixTable",
        name: "CapabilityMatrixTable",
        component: () => import("@/views/demo/CapabilityMatrixTable/index.vue"),
        meta: { title: "人员矩阵图",hidden: true,keepAlive: false, },
      },
      // D:\work\jtMom\xzjx-mom-web\src\views\demo\srmPurchaseDemand
      // 非菜单页面，在此添加路由 hidden: true
      // {
      //   path: "window7Add",
      //   name: "window7Add",
      //   component: () => import("@/views/demo/window7/add/index.vue"),
      //   meta: { hidden: true, title: "车载新建表单页" },
      // },
    ],
  },
  // 测试页面图例
  // {
  //   path: "/charts",
  //   component: Layout,
  //   name: "Charts",
  //   children: [
  //     {
  //       component: () => import("@/views/charts/index.vue"),
  //       path: "charts",
  //       name: "Charts",
  //       meta: {
  //         title: "echarts组件调用参考",
  //         icon: "link",
  //         keepAlive: true,
  //         hidden: false,
  //       },
  //     },
  //   ],
  // },

  // 外部链接
  // {
  //   path: "/external-link",
  //   component: Layout,
  //   children: [ {
  //       component: () => import("@/views/external-link/index.vue"),
  //       path: "https://www.cnblogs.com/haoxianrui/",
  //       meta: { title: "外部链接", icon: "link" },
  //     },
  //   ],
  // },
  // 多级嵌套路由
  /* {
         path: '/nested',
         component: Layout,
         redirect: '/nested/level1/level2',
         name: 'Nested',
         meta: {title: '多级菜单', icon: 'nested'},
         children: [
             {
                 path: 'level1',
                 component: () => import('@/views/nested/level1/index.vue'),
                 name: 'Level1',
                 meta: {title: '菜单一级'},
                 redirect: '/nested/level1/level2',
                 children: [
                     {
                         path: 'level2',
                         component: () => import('@/views/nested/level1/level2/index.vue'),
                         name: 'Level2',
                         meta: {title: '菜单二级'},
                         redirect: '/nested/level1/level2/level3',
                         children: [
                             {
                                 path: 'level3-1',
                                 component: () => import('@/views/nested/level1/level2/level3/index1.vue'),
                                 name: 'Level3-1',
                                 meta: {title: '菜单三级-1'}
                             },
                             {
                                 path: 'level3-2',
                                 component: () => import('@/views/nested/level1/level2/level3/index2.vue'),
                                 name: 'Level3-2',
                                 meta: {title: '菜单三级-2'}
                             }
                         ]
                     }
                 ]
             },
         ]
     }*/
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes as RouteRecordRaw[],
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
}

export default router;
